#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <stdlib.h>

void newlib_test1(void)
{
	static int i = 0;
	char *buf;

	printf("Hello newlib, %d\n", i++);
	buf = malloc(80);
	sprintf(buf, "ptr: 0x%08X\n", (int)buf);
	fputs(buf, stderr);
	free(buf);
	acoral_delay_self(100);
}

void newlib_test2(void)
{
	char *buf;

	enum {
		FGETS_BUFSIZE = 80,
	};

	buf = malloc(FGETS_BUFSIZE + 1);
	buf[FGETS_BUFSIZE] = '\0';

	fgets(buf, FGETS_BUFSIZE, stdin);
	fprintf(stderr, buf);
	free(buf);
}

void newlib_test3(void)
{
	int ch;

	ch = getchar();
	putchar(ch);
}

void newlib_testing(void *args)
{
	acoral_debugs("\r\n");
	acoral_debugs("Newlib testing started...\n");

	while ( 1 ) {
//		newlib_test1();
//		newlib_test2();
		newlib_test3();
	}
}
